package interview.blockqueue;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/****
 *
 *  传统版生产者与消费者
 *
 *
 */
class ShareData {
    public int a = 0;
    private Lock lock = new ReentrantLock();

    Condition condation = lock.newCondition();

    public void increase() {
            a = a + 1;
            System.out.println(Thread.currentThread().getName()+":"+a);
    }

    public void decrease() {
            a = a - 1;
            System.out.println(Thread.currentThread().getName()+":"+a);

    }

}

public class SimpleConsumerAndProduct {

    public static void main(String[] args) {
        ShareData share = new ShareData();
        new Thread(() -> {
            for (int i = 0; i < 15; i++) {
                share.increase();

            }

        }, "ppp").start();
        new Thread(() -> {
            for (int i = 0; i < 15; i++) {
                share.increase();

            }

        }, "RRR").start();



        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                share.decrease();
            }
        }, "AAA").start();
        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                share.decrease();
            }
        }, "BBB").start();
        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                share.decrease();
            }
        }, "CCC").start();

        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                share.decrease();
            }
        }, "DDD").start();
        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                share.decrease();
            }
        }, "EEE").start();
        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                share.decrease();
            }
        }, "FFF").start();




    }
}
